<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Card;
use Illuminate\Http\Request;

class CardController extends Controller
{
    public function index(Request $request) {
0
        $where  = $request->input('where');
        $where  = json_decode(json_encode($where));
        $code   = $where->code;
        $company= $where->company;
        $city   = $where->city;

        $card   = Card::with('companyinfo')->with('goodsinfo')->with('cityinfo');
        $company ? $card->where('company', $company) : null;
        $city ? $card->where('city_type', $city) : null;
        $code ?  $card->where('code', 'like', "%{$code}%") : '';
        $cards = $card->paginate(20);
        return self::success($cards);
    }
}
